<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Cache;
use think\queue\connector\Redis;


class Index extends UserAuth{
    /*
     //dump(phpinfo());exit;
        //return alert('请登录！',url('index/index'),5,2);exit;
        $redis = new \Redis();
        $redis->connect('127.0.0.1',6379);
        //$url = url('index/index');
        //$redis->set('url',$url);
        //dump($redis->get('url'));exit;
    */
    //后台首页 目录栏目
    //预交总学费
    public function sum_tuition(){
        $tuition =  Db::name("student")->sum('tuition');
        if($tuition){
            return show(1,'总额度为'.$tuition,$tuition);
        }else{
            return show(0,'查询失败');
        }
    }
    //当日充值总额
    public function today_tuition(){
        $str = '/学费充值/';
        $info = Db::name('account')
            ->select();
        $sum = 0;

        foreach($info as $k =>$v){
            $info[$k]['date_time'] = date('Y-m-d',$info[$k]['record_time']);
            if(date('Y-m-d') == $info[$k]['date_time']){
                if(preg_match($str,$info[$k]['cost_description'])){
                    $sum += strstr(trim($info[$k]['cost_description']),'+');
                }
            }
        }
        return show(1,'今日充值总额为'.$sum,$sum);
        //dump($result);die;
    }

    public function index(){

        if(request()->isGet()){
            //搜索菜单
            if(!empty($keywords)){
                $keywords = trim(input('get.keywords'));
                $where['list_name|frame_url'] = array("like", "%{$keywords}%");
                $list = Db::name('menu_list')
                    ->where(['pid'=>0])
                    ->where($where)
                    ->select();
            }elseif(empty($keywords)){
                $list = Db::name('menu_list')
                    ->where(['pid'=>0])
                    ->order('id')
                    ->select();
            }
        }else{
            $list = Db::name('menu_list')
                ->where(['pid'=>0])
                ->order('id')
                ->select();
        }

        foreach ($list as $k => $v) {
            $list[$k]['children'] = Db::name('menu_list')
                ->where(['pid'=>$v['id']])
                ->select();
        }
        //dump($_SERVER);die;
        $template = [
            'server_name' => $_SERVER['SERVER_NAME'],//服务器域名
            //'server_addr' => $_SERVER['SERVER_ADDR'],//服务器ip地址
            'server_port' => $_SERVER['SERVER_PORT'],//服务器端口
            'os' => PHP_OS,//服务器操作系统
            'document_root' => $_SERVER['DOCUMENT_ROOT'],//项目根目录
            //'windir' => $_SERVER['WINDIR'],//系统所在文件夹
            'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],//服务器语言种类
            'request_time' => $_SERVER['REQUEST_TIME'],//服务器当前时间
            //'home_driver' => $_SERVER['HOMEDRIVE'],//逻辑驱动器
           // 'processors_number' => $_SERVER['NUMBER_OF_PROCESSORS'],//CPU总数
            //'processors_identifier' => $_SERVER['PROCESSOR_IDENTIFIER'],//CPU类型
            //'session_name' => $_SERVER['SESSIONNAME'],//sessionname
           // 'username' => $_SERVER['USERNAME'],//系统用户名
            'server_software' => $_SERVER['SERVER_SOFTWARE'],//服务器环境
        ];

        $this->assign(
            [
                'list' => $list,
                'template' => $template,
            ]
        );
        return $this->fetch('template');
    }

}
